$(function(){
    FastClick.attach(document.body);
    getwd();
    pickjiedao();
    pickfuwu();

    $("body").on("click",".jd",function () {
        $(this).addClass("jdxz").siblings().removeClass("jdxz");
        if ($(this).text()!=="全部"){
            $(".wdCard").children().remove()
        var streetId = $(this).attr("id");
            if ($(".jg.jdxz").text()!=="全部"){
                var orgProperty = $(".jg.jdxz").attr("id");
                
                $.ajax({
                    url:requestUrl+"app/queryBranch.do",
                    type:"POST",
                    data:{streetId:streetId,orgProperty:orgProperty},
                    dataType:"JSON",
                    success:function(json){
                        if (json.code==0){
                        $(".wdCard").children().remove();
                            $(json.data).each(function (i,o) {
                                var div = $("<div class='wd-card' wdname='"+o.orgName+"'><div class='newsCdiv newsDivImg'><img src='images/wd1.png' class='news-img'></div><div class='newsCdiv newsInfo'><div class='news-titile'>"+o.orgName+"</div><div class='data'><span>电话："+o.telephone+"</span><span class='time'>地址："+o.address+"</span></div></div></div>").appendTo(".wdCard");
                            })
                        }else{
                                alert(json.message);
                            $(".wdCard").children().remove();
                        }
                    }
                })
            }else{
                $(".wdCard").children().remove()
                $.ajax({
                    url:requestUrl+"app/queryBranch.do",
                    type:"POST",
                    data:{streetId:streetId},
                    dataType:"JSON",
                    success:function(json){
                        if (json.code==0){
                            $(".wdCard").children().remove();
                            $(json.data).each(function (i,o) {
                                var div = $("<div class='wd-card' wdname='"+o.orgName+"'><div class='newsCdiv newsDivImg'><img src='images/wd1.png' class='news-img'></div><div class='newsCdiv newsInfo'><div class='news-titile'>"+o.orgName+"</div><div class='data'><span>电话："+o.telephone+"</span><span class='time'>地址："+o.address+"</span></div></div></div>").appendTo(".wdCard");
                            })
                        }else{
                            alert(json.message);
                            $(".wdCard").children().remove();
                        }
                    }
                })
            }
        }else{
            $(".wdCard").children().remove()
            if ($(".jg.jdxz").text()!=="全部"){
                var orgProperty = $(".jg.jdxz").attr("id");
                
                $.ajax({
                    url:requestUrl+"app/queryBranch.do",
                    type:"POST",
                    data:{orgProperty:orgProperty},
                    dataType:"JSON",
                    success:function(json){
                        if (json.code==0){
                            $(".wdCard").children().remove();
                            $(json.data).each(function (i,o) {
                                var div = $("<div class='wd-card' wdname='"+o.orgName+"'><div class='newsCdiv newsDivImg'><img src='images/wd1.png' class='news-img'></div><div class='newsCdiv newsInfo'><div class='news-titile'>"+o.orgName+"</div><div class='data'><span>电话："+o.telephone+"</span><span class='time'>地址："+o.address+"</span></div></div></div>").appendTo(".wdCard");
                            })
                        }else{
                            alert(json.message);
                            $(".wdCard").children().remove();
                        }
                    }
                })
            }else{
                getwd();
            }
        }
    })
    $("body").on("click",".jg",function () {
        $(this).addClass("jdxz").siblings().removeClass("jdxz");
        if ($(this).text()!=="全部"){
            $(".wdCard").children().remove()
            var orgProperty= $(this).attr("id");
            if ($(".jd.jdxz").text()!=="全部"){
                var streetId = $(".jg.jdxz").attr("id");
                $(".wdCard").children().remove()
                $.ajax({
                    url:requestUrl+"app/queryBranch.do",
                    type:"POST",
                    data:{streetId:streetId,orgProperty:orgProperty},
                    dataType:"JSON",
                    success:function(json){
                        if (json.code==0){
                            $(".wdCard").children().remove();
                            $(json.data).each(function (i,o) {
                                var div = $("<div class='wd-card' wdname='"+o.orgName+"'><div class='newsCdiv newsDivImg'><img src='images/wd1.png' class='news-img'></div><div class='newsCdiv newsInfo'><div class='news-titile'>"+o.orgName+"</div><div class='data'><span>电话："+o.telephone+"</span><span class='time'>地址："+o.address+"</span></div></div></div>").appendTo(".wdCard");
                            })
                        }else{
                            alert(json.message);
                            $(".wdCard").children().remove();
                        }
                    }
                })
            }else{
                $.ajax({
                    url:requestUrl+"app/queryBranch.do",
                    type:"POST",
                    data:{orgProperty:orgProperty},
                    dataType:"JSON",
                    success:function(json){
                        $(".wdCard").children().remove();
                        if (json.code==0){
                            $(json.data).each(function (i,o) {
                                var div = $("<div class='wd-card' wdname='"+o.orgName+"'><div class='newsCdiv newsDivImg'><img src='images/wd1.png' class='news-img'></div><div class='newsCdiv newsInfo'><div class='news-titile'>"+o.orgName+"</div><div class='data'><span>电话："+o.telephone+"</span><span class='time'>地址："+o.address+"</span></div></div></div>").appendTo(".wdCard");
                            })
                        }else{
                            alert(json.message);
                            $(".wdCard").children().remove();
                        }
                    }
                })
            }
        }else{
            $(".wdCard").children().remove()
            if ($(".jd.jdxz").text()!=="全部"){
                var streetId = $(".jd.jdxz").attr("id");
                $.ajax({
                    url:requestUrl+"app/queryBranch.do",
                    type:"POST",
                    data:{streetId:streetId},
                    dataType:"JSON",
                    success:function(json){
                        if (json.code==0){
                            $(".wdCard").children().remove();
                            $(json.data).each(function (i,o) {
                                var div = $("<div class='wd-card' wdname='"+o.orgName+"'><div class='newsCdiv newsDivImg'><img src='images/wd1.png' class='news-img'></div><div class='newsCdiv newsInfo'><div class='news-titile'>"+o.orgName+"</div><div class='data'><span>电话："+o.telephone+"</span><span class='time'>地址："+o.address+"</span></div></div></div>").appendTo(".wdCard");
                            })
                        }else{
                            alert(json.message);
                            $(".wdCard").children().remove();
                        }
                    }
                })
            }else{
                getwd();
            }
        }
    })

    $("body").on("click",".wd-card",function () {
        window.localStorage.wdname = $(this).attr("wdname");
        window.location.href="wdinfo.html";
    })
})

function pickjiedao() {
    $.ajax({
        url:requestUrl+"app/queryAllBranchStreet.do",
        type:"GET",
        dataType:"JSON",
        success:function(json){
            if (json.code==0){
            if (json.data.length!==0){
                $(json.data).each(function (i, o) {
                    var jd = $("<div class='jd' id='"+o.id+"'>"+o.name+"</div>").appendTo(".jiedaozi");
                })
            }
            }else{
            alert(json.message);
            }
        }
    })

}
function pickfuwu() {
    $.ajax({
        url: requestUrl + "app/queryOrgProperty.do",
        type: "GET",
        dataType: "JSON",
        success: function (json) {
            if (json.code == 0) {
                if (json.data.length !== 0) {
                    var jdArr = [];
                    $(json.data).each(function (i, o) {
                        var jd = $("<div class='jg' id='"+o.id+"'>"+o.name+"</div>").appendTo(".jigouzi");
                    })
                }
            }
        }

    })

}



function getwd() {

    $.ajax({
        url:requestUrl+"app/queryBranch.do",
        type:"GET",
        dataType:"JSON",
        success:function(json){
            if (json.code==0){
                $(".wdCard").children().remove()
                $(json.data).each(function (i,o) {
                    var div = $("<div class='wd-card' wdname='"+o.orgName+"'><div class='newsCdiv newsDivImg'><img src='images/wd1.png' class='news-img'></div><div class='newsCdiv newsInfo'><div class='news-titile'>"+o.orgName+"</div><div class='data'><span>电话："+o.telephone+"</span><span class='time'>地址："+o.address+"</span></div></div></div>").appendTo(".wdCard");
                })
            }else{
                if(json.message=="用户尚未登陆"){
                    window.location.href="login.html";
                }else{
                    alert(json.message);
                }
            }
        }
    })
}